﻿namespace IBTrader.Charts.Legend
{
    using IBTrader.Modules.Read;
    using System.Drawing;

    class LegendText : BaseChart
    {
        private Line volume;
        private readonly string symbol;
        public LegendText(Worker worker, string symbol) : base(worker)
        {
            this.symbol = symbol;
            //worker.Reader.Volume += (_, line) => volume = line;
        }
        public override void Add(object _, Line line)
        {
            volume = line;
        }
        public override void Draw(IGraphics g, Charts.Region region)
        {
            //Func<Charts.Region.Point, float> f = p => (float)(p.Min + (p.Max - p.Min) / 100);
            if (volume == null) return;
            var dt = volume.DateTime.Date;
            var brush = new SolidBrush(Color);
            //var x = (float)region.XValue( f(region.X));
            //var y = (float)region.YValue(f(region.Y));
            g.FillRectangle(new SolidBrush(Color.White), new RectangleF(new PointF(11, 11), new SizeF(150, 30)));
            g.DrawString(dt.ToString("ddd,dd-MMM-yyyy") + " " + symbol, Font, brush, new PointF(11, 11));
            g.DrawString(string.Format("Volume {0:0,0}", volume.Price), Font, brush, new PointF(11, 25));
        }
    }
}